import os
import subprocess
import shutil

script_dir = os.path.dirname(os.path.abspath(__file__))
base_dir = os.path.abspath(os.path.join(script_dir, "../packages"))

if not os.path.exists(base_dir):
    print(f"目录不存在: {base_dir}")
    exit(1)

pnpm_path = shutil.which("pnpm")
if pnpm_path is None:
    print("未找到 pnpm 命令，请检查环境变量。")
    exit(1)

for name in os.listdir(base_dir):
    folder = os.path.join(base_dir, name)
    if os.path.isdir(folder):
        print(f"正在初始化: {folder}")
        subprocess.run([pnpm_path, "init"], cwd=folder)